import com.aliyun.odps.utils.StringUtils;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Res_fault {
   // private String s;
    public Res_fault(){

    }

    public String code_descroption(String s) {
        String result = "";
        StringBuffer sb = new StringBuffer();
        String code = "";
        String fault_description = "";
        if(s=="" || s==null){
            result = "没有故障码";

        }else {

            Pattern pattern = Pattern.compile("\"code\" *: *\"([A-Za-z0-9]+?)\"[\\s\\S]*?fault_description\" *: *\"([^\"]+)\"");

            Matcher matcher = pattern.matcher(s);
            Set<String> set = new HashSet<String>();
            Map<String ,String> map = new HashMap<>();
            if(matcher.find()){
                code = matcher.group(1);
                fault_description = matcher.group(2);
                if(code!="" && code!=null && fault_description!="" && fault_description!=null) {
                    map.put(code, fault_description);
                }
                //System.out.println("code"+code);
                //System.out.println("description"+fault_description);
                while (matcher.find()) {
                    code = matcher.group(1);
                    fault_description = matcher.group(2);
                    if(code!="" && code!=null && fault_description!="" && fault_description!=null) {
                        map.put(code, fault_description);
                    }

                    //System.out.println("code"+code);
                    //System.out.println("description"+fault_description);

                }
                result = "";
                for (String key : map.keySet()) {
                    sb.append(key +"qaz123"+map.get(key)+"QAZ123");
                }
                result = sb.substring(0,sb.length()-6);


            }else {
                result = "没有故障码";
            }





        }
        return result;

    }
















}
